package com.niit.project.dao.impl;

import com.niit.project.dao.AdminDao;
import com.niit.project.entity.Admin;
import com.niit.project.utils.Dbutils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class AdminDaoImpl implements AdminDao {
    QueryRunner queryRunner = new QueryRunner();

    @Override
    public Admin select(String name) {          //将所有管理员的信息查找出来并存储到Admin实体类中,将来用于管理员登录的验证
        try {
            Admin admin = queryRunner.query(Dbutils.getConnection(),"select * from admin where name = ?",new BeanHandler<Admin>(Admin.class),name);
            return admin;           //将admin对象返回,即哪里调用这个方法,就可以获得这个返回对象
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
